﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Eventing.Reader;

namespace org.swinchester.windowsevents.core
{
    public class EventReaderBase
    {
        public EventSubscriptionConfig SubscriptionConfig { get; set; }
        public event GenericEventRecordHandler EventRecordRead;
        public delegate void GenericEventRecordHandler(object sender, EventArgs e);

        public void EventLogEventRead(object sender,
            EventRecordWrittenEventArgs arg)
        {
            // Make sure there was no error reading the event.
            if (arg != null)
            {
                if (arg.EventRecord != null)
                {
                    EventRecordRead(arg.EventRecord, arg);
                }
                else
                {
                    Console.WriteLine("The event instance was null.");
                }
            }
            else
            {
                EventRecordRead((EventRecord)sender, null);
            }
        }
    }
}
